package tw.edu.tku.im.maze;

import org.json.JSONException;
import org.json.JSONObject;

public class MarkReqParser extends PacketParser {
   public static MarkReqParser INSTANCE = new MarkReqParser();
   
   private MarkReqParser() { }

   @Override
   public MarkReq parse(JSONObject jsonObj) throws JSONException {
      JSONObject parameter = jsonObj.getJSONObject("parameter");
      int roomID = parameter.getInt("roomID");
      String userID = parameter.getString("userID");
      int ticket = parameter.getInt("ticket");
      MazeCell mark = MazeCell.parse(parameter.getJSONObject("mark"));
      boolean markAction = parameter.getBoolean("markAction");
      if(parameter.isNull("lastTimestamp")) {
         return new MarkReq(roomID, userID, ticket, mark, markAction);
      }
      else {
         String lastTimestamp = parameter.getString("lastTimestamp");
         return new MarkReq(roomID, userID, ticket, lastTimestamp, mark, markAction);
      }
   }
   
   @Override
   public String acceptName() {
      return "mark";
   }

}
